package com.xinghe.sharedevice.controller;

import com.share.common.core.web.controller.BaseController;
import com.share.common.core.web.domain.AjaxResult;
import com.share.common.core.web.page.TableDataInfo;
import com.share.common.security.utils.SecurityUtils;
import com.xinghe.sharedevice.domain.PowerBank;
import com.xinghe.sharedevice.service.IPowerBankService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Date;
import java.util.List;

/**
 * @author 星河一叶Ck
 * @date 2025/5/27
 */

@Tag(name = "充电宝接口管理")
@RestController
@RequestMapping("/powerBank")
@RequiredArgsConstructor
public class PowerBankController extends BaseController {

    private final IPowerBankService powerBankService;

    /**
     * 查询充电宝列表
     * @param powerBank 充电宝
     * @return TableDataInfo
     */
    @Operation(summary = "查询充电宝列表")
    @GetMapping("/list")
    public TableDataInfo list(PowerBank powerBank) {
        startPage();
        List<PowerBank> list = powerBankService.selectPowerBankList(powerBank);
        return getDataTable(list);
    }

    /**
     * 查询充电宝详细信息
     * @param id 充电宝id
     * @return 详细信息
     */
    @Operation(summary = "查询充电宝详细信息")
    @GetMapping("/{id}")
    public AjaxResult getInfo (@PathVariable("id") Long id) {
        return success(powerBankService.getById(id));
    }

    /**
     * 新增充电宝
     * @param powerBank 要新增的充电宝数据
     * @return 成功与否
     */
    @Operation(summary = "新增充电宝")
    @PostMapping
    public AjaxResult add(@RequestBody PowerBank powerBank) {
        return toAjax(powerBankService.savePowerBank(powerBank));
    }

    /**
     * 修改充电宝
     * @param powerBank 要修改的充电宝数据
     * @return 成功与否
     */
    @Operation(summary = "修改充电宝")
    @PutMapping
    public AjaxResult edit (@RequestBody PowerBank powerBank) {
        return toAjax(powerBankService.updatePowerBank(powerBank));
    }

    @Operation(summary = "删除充电宝")
    @DeleteMapping("/{ids}")
    public AjaxResult remove (@PathVariable Long[] ids) {
        return toAjax(powerBankService.removeBatchByIds(Arrays.asList(ids)));
    }
}
